package com.saturn.highcharts;

import java.util.List;

import org.json.JSONObject;

public class Pie {
	private String name = "";
	private String data = "";
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getData() {
		return data;
	}
	public void setData(String data) {
		this.data = data;
	}
	
	public static String getPieJSON(List<Pie> cts) {

		StringBuffer buffer = new StringBuffer();
		buffer.append("{");

		buffer.append("\"rows\":");
		buffer.append("[{");
		buffer.append("\"name\":" + "\"ss\"");
		buffer.append(",");
		buffer.append("\"data\":[");
		for (int i = 0; i < cts.size(); i++) {
			buffer.append("[");
			buffer.append("\"" + cts.get(i).getName() + "\"," + cts.get(i).getData());
			
			if (i == (cts.size()-1)) {
				buffer.append("]");
			} else {
				buffer.append("], ");
			}
			
		}
		buffer.append("]");
		buffer.append("}");
		buffer.append("]");
		buffer.append("}");
		System.out.println(buffer.toString());
		return buffer.toString();
	}
	
	@Override
	public String toString() {
		return new JSONObject(this).toString();
	}
}
